<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>

        function inheritPrototype(subType, superType) {
            // 创建对象
            var prototype = Object.create(superType.prototype);

            // 增强对象
            prototype.constructor = subType;

            // 指定对象
            subType.prototype = prototype;
        }



        function Super(name) {
            this.name = name;
            this.colors = ['red', 'blue'];
        }

        Super.prototype.sayName = function () {
            alert(this.name);
        };

        function Sub(name, age) {
            // 继承属性
            Super.call(this, name);
            this.age = age;
        }

        inheritPrototype(Sub, Super); // 调用寄生组合继承方法

        Sub.prototype.sayAge = function () {
            alert(this.age);
        };
        var sub=new Sub("yangtao",18);
        sub.sayName();
        sub.sayAge();
    </script>
</head>
<body>
寄生组合继承
</body>
</html>